package com.copractice.beans.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Represents user session.
 * Used for transferring data between pages.
 * 
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/28/2009
 */
@SuppressWarnings("serial")
public class UserSession implements Serializable {
    
    /**
     * Stores session specific data. Data is saved as a key-value pair.
     */
    private Map<String, Object> data = new HashMap<String, Object>();
    
    /**
     * Returns the value to which the specified key is mapped,
     * or {@code null} if this key is not mapped to any value.
     *
     * @param key the key whose associated value is to be returned
     * @return data the value to which the specified key is mapped
     */
    public synchronized Object getAttribute(String key) {
        return data.get(key);
    }

    /**
     * Associates the specified value with the specified key in the session.
     *
     * @param key key with which the specified value is to be associated
     * @param value value to be associated with the specified key
     */
    public synchronized void setAttribute(String key, Object value) {
        data.put(key, value);
    }
    
}
